package com.baizhi.service.impl;

import com.baizhi.entity.PmsBrand;
import com.baizhi.entity.PmsCategoryBrandRelation;
import com.baizhi.mapper.PmsBrandMapper;
import com.baizhi.mapper.PmsCategoryBrandRelationMapper;
import com.baizhi.service.PmsBrandService;
import com.baizhi.vo.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yu
 */
@Service
public class PmsBrandServiceImpl implements PmsBrandService {
    @Autowired
    private PmsBrandMapper pmsBrandMapper;
    @Autowired
    private PmsCategoryBrandRelationMapper pmsCategoryBrandRelationMapper;
    @Override
    public R showPmsBrandByCategoryId(Long categoryId) {

        List<PmsCategoryBrandRelation> relationList = pmsCategoryBrandRelationMapper.selectList(new QueryWrapper<PmsCategoryBrandRelation>().eq("category_id", categoryId));
        ArrayList<Long> longs = new ArrayList<>();
        for (PmsCategoryBrandRelation pmsCategoryBrandRelation : relationList) {
            longs.add(pmsCategoryBrandRelation.getBrandId());
        }
        if (longs.size()>0){
            List<PmsBrand> pmsBrands = pmsBrandMapper.selectList(new QueryWrapper<PmsBrand>().in("brand_id", longs));

            return R.ok().put("data",pmsBrands);
        }
        return R.ok();
    }
}
